home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / referenceEditorPanel.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  19.9 KB  |  779 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. // Alias|Wavefront Script File
  19. // MODIFY THIS AT YOUR OWN RISK
  20. //
  21. // Creation Date:  Dec 3 1998
  22. // Author:         cdt
  23. //
  24. //  Procedure Name:
  25. //      referenceEditorPanel
  26. //
  27. //  Description:
  28. //      Creates a panel that contains a reference editor.
  29. //
  30. //  Input Arguments:
  31. //      None
  32. //
  33. //  Return Value:
  34. //      None.
  35. //
  36.  
  37. global string $_selectedFile[];
  38. global string $_selectedRef[];
  39.  
  40. global proc referenceEdFileSelected(string $whichPanel)
  41. {
  42.     global string $_selectedFile[];
  43.     global string $_selectedRef[];
  44.     string $activeFile;
  45.     
  46.     $_selectedFile = `sceneEditor -q -si 
  47.                      ($whichPanel + "referenceEditorPanel")`;
  48.     $_selectedRef = `sceneEditor -q -sr 
  49.                     ($whichPanel + "referenceEditorPanel")`;
  50.     
  51.     if (size($_selectedFile) == 1
  52.                 && size($_selectedFile[0]) > 0
  53.                 && `file -q -ex $_selectedFile[0]`) {
  54.         
  55.         $activeFile = `file -q -a $_selectedFile[0]`;
  56.  
  57.         text -e -l $_selectedFile[0] fileNameValue;
  58.         string $fileType[] = `file -q -type $_selectedFile[0]`;
  59.         if (size($fileType) > 0) {
  60.             text -e -l $fileType[0] fileTypeValue;
  61.         } else {
  62.             text -e -l "Unknown" fileTypeValue;
  63.         }
  64.  
  65.         string $subType = `file -q -st $_selectedFile[0]`;
  66.         text -e -l $subType fileSubTypeValue;
  67.  
  68.         int $writable = `file -q -w $_selectedFile[0]`;
  69.         if ($writable) {
  70.             text -e -l "Writable" fileIOValue;
  71.         } else {
  72.             text -e -l "Read Only" fileIOValue;
  73.         }
  74.         int $modified = `file -q -mf $_selectedFile[0]`;
  75.         if ($modified) {
  76.             text -e -l "Modified" fileStatusValue;
  77.         } else {
  78.             text -e -l "Not Modified" fileStatusValue;
  79.         }
  80.  
  81.         int $deferred = `file -q -dr $_selectedFile[0]`;
  82.         if ($deferred) {
  83.             text -e -l "Unloaded" fileLoadValue;
  84.         } else {
  85.             text -e -l "Loaded" fileLoadValue;
  86.         }
  87.  
  88.         string $renamePrefix = `file -q -rpr $_selectedFile[0]`;
  89.         text -e -l $renamePrefix fileRenamePrefixValue;
  90.     } else {
  91.         // Nothing selected.
  92.         //
  93.         string $notAvailable = "N/A";
  94.         text -e -l $notAvailable fileTypeValue;
  95.         text -e -l $notAvailable fileSubTypeValue;
  96.         text -e -l $notAvailable fileIOValue;
  97.         text -e -l $notAvailable fileStatusValue;
  98.         text -e -l $notAvailable fileLoadValue;
  99.         text -e -l $notAvailable fileNameValue;
  100.         text -e -l $notAvailable fileRenamePrefixValue;
  101.     }
  102. }
  103.  
  104. //    MENU CREATION PROCEDURES
  105. //
  106.  
  107. global proc buildReferenceFileMenu(string $parentMenu)
  108. //
  109. //    Description:
  110. //        Builds the submenu for file functionality in the reference editor.
  111. //
  112. {
  113.     setParent -menu $parentMenu;
  114.     
  115.     if (`menu -query -numberOfItems $parentMenu` == 0) {
  116.         menuItem 
  117.             -label "Create Reference"
  118.             -command ("CreateReference")
  119.             referenceEdCreateItem;
  120.         menuItem -optionBox true
  121.             -l "Create Reference Option Box"
  122.             -c "fileOptions \"Reference\" \"projectViewer Reference\"" 
  123.             referenceEdFileOptions;
  124.  
  125.         menuItem 
  126.             -label "Import Objects from Reference"
  127.             -command referenceEdImportCB
  128.             referenceEdImportItem;
  129.  
  130.         menuItem 
  131.             -label "Export Selection as a Reference"
  132.             -command "referenceEdExportCB"
  133.             referenceEdExportItem;
  134.  
  135.         menuItem -divider true;
  136.  
  137.         menuItem
  138.             -label "Clean Up Reference"
  139.             -command "referenceEdCleanUpCB"
  140.             referenceEdCleanUpItem;
  141.     }
  142.  
  143.     updateReferenceFileMenu($parentMenu);
  144. }
  145.  
  146. global proc updateReferenceFileMenu(string $parentMenu)
  147. //
  148. //    Description:
  149. //        Updates the file menu in the reference editor.
  150. //
  151. {
  152.     global string $_selectedRef[];
  153.  
  154.     string $oldParent = `setParent -q -menu`;
  155.     setParent -menu $parentMenu;
  156.  
  157.     //    Disable the export item if the selection list is empty.
  158.     //
  159.     int $exportEnable = (size(`ls -sl`) > 0) ? true : false;
  160.     menuItem -edit -enable $exportEnable referenceEdExportItem;
  161.  
  162.     //    Disable the clean reference item if there is no reference node.
  163.     //
  164.     int $cleanEnable = 1;
  165.     if (size($_selectedRef) == 0 || size($_selectedRef[0]) == 0) {
  166.         $cleanEnable = 0;
  167.     }
  168.     menuItem -edit -enable $cleanEnable referenceEdCleanUpItem;
  169.  
  170.     setParent -menu $oldParent;
  171. }
  172.  
  173. global proc buildReferenceEditMenu(string $parentMenu)
  174. //
  175. //    Description:
  176. //        Builds the Edit submenu for the reference editor.
  177. //
  178. {
  179.     setParent -menu $parentMenu;
  180.  
  181.     if (`menu -query -numberOfItems $parentMenu` == 0) {
  182.         menuItem 
  183.             -label "Remove Reference"
  184.             -command "referenceEdRemoveCB"
  185.             referenceEdRemoveItem;
  186.  
  187.         menuItem 
  188.             -label "Select File Contents"
  189.             -command "referenceEdSelectCB"
  190.             referenceEdSelectItem;
  191.     }
  192.  
  193.     updateReferenceEditMenu($parentMenu);
  194. }
  195.  
  196. global proc updateReferenceEditMenu(string $parentMenu)
  197. //
  198. //    Description:
  199. //        Updates the edit menu for the reference editor.
  200. //
  201. {
  202.     global string $_selectedFile[];
  203.     global string $_selectedRef[];
  204.  
  205.     string $oldParent = `setParent -q -menu`;
  206.     setParent -menu $parentMenu;
  207.  
  208.     int $enable = (size($_selectedFile) > 0) ? true : false;
  209.     menuItem -edit -enable $enable referenceEdSelectItem;
  210.  
  211.     setParent -menu $oldParent;
  212. }
  213.  
  214. global proc buildReferenceReferenceMenu(string $parentMenu)
  215. //
  216. //    Desciption:
  217. //
  218. //
  219. {
  220.     setParent -menu $parentMenu;
  221.  
  222.     if (`menu -query -numberOfItems $parentMenu` == 0) {
  223.         menuItem
  224.             -label "Load Reference"
  225.             -command referenceEdLoadCB
  226.             referenceEdLoadItem;
  227.  
  228.         menuItem
  229.             -label "Unload Reference"
  230.             -command referenceEdUnloadCB
  231.             referenceEdUnloadItem;
  232.  
  233.         menuItem -divider true;
  234.  
  235.         menuItem
  236.             -label "Replace Reference"
  237.             -command referenceEdReplaceCB
  238.             referenceEdReplaceItem;
  239.  
  240.         menuItem 
  241.             -subMenu true
  242.             -label "Recent Files"
  243.             -postMenuCommand ("buildReferenceEdRecentMenu " + $parentMenu)
  244.             referenceEdRecentFilesItem;
  245.     }
  246.  
  247.     updateReferenceReferenceMenu($parentMenu);
  248. }
  249.  
  250. global proc updateReferenceReferenceMenu(string $parentMenu)
  251. //
  252. //    Description:
  253. //        Updates the reference menu for the reference editor.
  254. //
  255. {
  256.     global string $_selectedRef[];
  257.  
  258.     string $oldParent = `setParent -q -menu`;
  259.     setParent -menu $parentMenu;
  260.  
  261.     setParent -menu $oldParent;
  262. }
  263.  
  264. //    END OF MENU CREATION PROCEDURES
  265. //
  266.  
  267. global proc referenceEditorPanel(string $panelName) {
  268.  
  269.     global string $gMainPane;
  270.  
  271.     if (!`scriptedPanelType -exists referenceEditorPanel`) {
  272.         scriptedPanelType 
  273.             -createCallback "createRefEdPanel"
  274.             -addCallback     "addRefEdPanel" 
  275.             -removeCallback "removeRefEdPanel"
  276.             referenceEditorPanel;
  277.  
  278.         setParent $gMainPane;
  279.         scriptedPanel -unParent -type "referenceEditorPanel" $panelName;
  280.     }
  281. }
  282.  
  283. global proc createRefEdPanel(string $whichPanel) {
  284.     sceneEditor 
  285.         -unParent
  286.         -selectCommand ("referenceEdFileSelected \"" + $whichPanel + "\"")
  287.         ($whichPanel + "referenceEditorPanel");
  288. }
  289.  
  290. global proc buildReferenceContextHelpItems(string $nameRoot, string $menuParent)
  291. //
  292. //  Description:
  293. //        Build context sensitive menu items for the hyper shader.  
  294. //        
  295. //  Input Arguments:
  296. //        $nameRoot - name to use as the root of all item names
  297. //        $menuParent - the name of the parent of this menu
  298. //
  299. //  Return Value:
  300. //      None
  301. //
  302. {
  303.     menuItem -label "Help on Reference Editor..."
  304.         -enableCommandRepeat false
  305.         -command "showHelp ReferenceEditor";
  306. }
  307.  
  308. global proc addRefEdPanel( string $whichPanel ) {
  309. global int $gStandardIdent;
  310.     int $numDivisions = 100;
  311.  
  312.     string $rp = ($whichPanel + "referenceEditorPanel");
  313.  
  314.     //    Add the menu.
  315.     //
  316.     string $fileMenu = `menu -label "File"
  317.                        -allowOptionBoxes true
  318.                        -tearOff true`;
  319.     menu -edit 
  320.         -postMenuCommand ("updateReferenceFileMenu " + $fileMenu)
  321.         $fileMenu;
  322.     buildReferenceFileMenu($fileMenu);
  323.     setParent -menu ..;
  324.  
  325.     string $editMenu = `menu -label "Edit"
  326.                        -allowOptionBoxes true
  327.                        -tearOff true`;
  328.     menu -edit 
  329.         -postMenuCommand ("updateReferenceEditMenu " + $editMenu)
  330.         $editMenu;
  331.     buildReferenceEditMenu($editMenu);
  332.     setParent -menu ..;
  333.  
  334.     string $referenceMenu = `menu -label "Reference"
  335.                             -allowOptionBoxes true
  336.                             -tearOff true`;
  337.     
  338.     menu -edit
  339.         -postMenuCommand ("buildReferenceReferenceMenu " + $referenceMenu)
  340.         $referenceMenu;
  341.     setParent -menu ..;
  342.  
  343.     //    Add support for the Context Sensitive Help Menu.
  344.     //
  345.     addContextHelpProc $whichPanel "buildReferenceContextHelpItems";
  346.  
  347.     string $edParent = `formLayout`;
  348.     string $outlinerLayout = `formLayout`;
  349.     sceneEditor -e 
  350.         -parent $outlinerLayout $rp;
  351.  
  352.     setParent ..;
  353.  
  354.     formLayout -e 
  355.         -af $rp top 0
  356.         -af $rp left 0 
  357.         -af $rp right 0
  358.         -af $rp bottom 0
  359.         $outlinerLayout;
  360.  
  361.         frameLayout 
  362.             -l "File Particulars" 
  363.             -cll true 
  364.             -cl `optionVar -q refEdFilePartCl`
  365.             -cc "optionVar -iv refEdFilePartCl 1"
  366.             -ec "optionVar -iv refEdFilePartCl 0"
  367.             -labelIndent $gStandardIdent
  368.             fileInfoFrame;
  369.  
  370.             string $fInfoForm = `formLayout -nd $numDivisions fileInfoForm`;
  371.                 text -l "Name:" fileNameLabel;
  372.                 text fileNameValue;
  373.                 text -l "Type:" fileTypeLabel;
  374.                 text fileTypeValue;
  375.                     text -l "Sub-Type:" fileSubTypeLabel;
  376.                     text fileSubTypeValue;
  377.                     text -l "Status:" fileStatusLabel;
  378.                     text fileStatusValue;
  379.                     text -l "Load:" fileLoadLabel;
  380.                     text fileLoadValue;
  381.                     text -l "I/O:" fileIOLabel;
  382.                     text fileIOValue;
  383.                     text -l "Rename Prefix:" fileRenamePrefixLabel;
  384.                     text fileRenamePrefixValue;
  385.                 
  386.         formLayout -e
  387.             -af fileNameLabel left 0 -af fileNameLabel top 0
  388.             -ap fileNameValue left 0 15 -af fileNameValue top 0
  389.             -af fileTypeLabel left 0 -ac fileTypeLabel top 0 fileNameLabel
  390.             -ap fileTypeValue left 0 15 -ac fileTypeValue top 0 fileNameLabel
  391.             -ap fileSubTypeLabel left 0 50  
  392.                 -ac fileSubTypeLabel top 0 fileNameLabel
  393.             -ap fileSubTypeValue left 0 70 
  394.                 -ac fileSubTypeValue top 0 fileNameLabel
  395.             -af fileStatusLabel left 0 
  396.                 -ac fileStatusLabel top 0 fileSubTypeLabel
  397.             -ap fileStatusValue left 0 15 
  398.                 -ac fileStatusValue top 0 fileSubTypeLabel
  399.             -ap fileIOLabel left 0 50  -ac fileIOLabel top 0 fileSubTypeLabel
  400.             -ap fileIOValue left 0 70 -ac fileIOValue top 0 fileSubTypeLabel
  401.             -af fileLoadLabel left 0
  402.                 -ac fileLoadLabel top 0 fileIOLabel
  403.             -ap fileLoadValue left 0 15
  404.                 -ac fileLoadValue top 0 fileIOLabel
  405.             -ap fileRenamePrefixLabel left 0 50  
  406.                 -ac fileRenamePrefixLabel top 0 fileIOLabel
  407.             -ap fileRenamePrefixValue left 0 70 
  408.                 -ac fileRenamePrefixValue top 0 fileIOLabel
  409.             $fInfoForm;
  410.  
  411.         formLayout -e
  412.             -af fileInfoFrame top 0
  413.             -af fileInfoFrame left 0
  414.             -af fileInfoFrame right 0
  415.             -ac $outlinerLayout top 5 fileInfoFrame
  416.             -af $outlinerLayout left 0
  417.             -af $outlinerLayout right 0
  418.             -af $outlinerLayout bottom 0
  419.             $edParent;
  420.         
  421.         setParent $edParent;
  422.  
  423.         source ReferenceEdMenu;
  424.         ReferenceEdMenu($whichPanel);
  425.  
  426.         referenceEdFileSelected($whichPanel);
  427. }
  428.     
  429. global proc removeRefEdPanel(string $whichPanel)
  430. {
  431.     sceneEditor -e -unParent
  432.         ($whichPanel + "referenceEditorPanel");
  433. }
  434.  
  435. //    Global procs used by the menus...
  436. //
  437.  
  438. global proc referenceEdImportCB()
  439. //
  440. //    Description:
  441. //        Import the contents of a reference file into the scene. The imported
  442. //        file is no longer referenced.
  443. //
  444. {
  445.     global string $_selectedFile[];
  446.     if (size($_selectedFile) == 1 && size($_selectedFile[0]) > 0) {
  447.         file -ir $_selectedFile[0];
  448.     }
  449. }
  450.  
  451. global proc referenceEdCleanUpCB()
  452. //
  453. //    Description:
  454. //        Cleans up the currently selected reference. Any unresolved information
  455. //        is removed. This is a potentially dangerous option.
  456. //
  457. {
  458.     global string $_selectedRef[];
  459.  
  460.     //    If a reference node is not selected, then there is nothing to
  461.     //    clean up.
  462.     //
  463.     if (size($_selectedRef) == 0 || size($_selectedRef[0]) == 0) {
  464.         return;
  465.     }
  466.  
  467.     string $result = `confirmDialog -t "Clean Reference"
  468.                         -m ("Cleaning up the reference node, "
  469.                         +$_selectedRef[0]+", is Not Undoable.")
  470.                         -b "Clean" -b "Cancel" -db "Cancel"`;
  471.     if ($result == "Clean") {
  472.         file -cr $_selectedRef[0];
  473.     }
  474. }
  475.  
  476. global proc int referenceEdExportAsReference(string $theFile, string $fileType)
  477. //
  478. //    Description:
  479. //        This code is used to create a reference file from a
  480. //        selection in the current scene. 
  481. //
  482. //    Note:
  483. //        There are currently no options associated with this action so
  484. //        we must use the currently set Export Selected options. Note that
  485. //        we cannot ignore history during this operation. This case is
  486. //        handled in the export code.
  487. //
  488. {
  489.     int $fileExists = `file -q -ex $theFile`;
  490.  
  491.     int $win32 = `about -nt`;
  492.     if ($fileExists && !$win32) {
  493.         string $result = `confirmDialog -m "File Exists. Overwrite?" 
  494.             -b "Yes" -b "Cancel" -db "Cancel" -parent projectViewerWindow`;
  495.         if ($result == "Cancel") {
  496.             return false;
  497.         } 
  498.     }
  499.         
  500.         if (`about -evalVersion`) {
  501.         $fileType = "mayaPLE";
  502.     } else     if ($fileType == "") {
  503.         $fileType = "mayaBinary";
  504.     }
  505.  
  506.     string $fileOptions;
  507.     string $translatorOptions = ($fileType+"Options");
  508.     if (`optionVar -exists $translatorOptions`) {
  509.         // Post the new options.
  510.         $fileOptions = `optionVar -q $translatorOptions`;
  511.     } 
  512.  
  513.     file -f -op $fileOptions -typ $fileType -er $theFile;
  514.  
  515.     return true;
  516. }
  517.  
  518. global proc referenceEdExportCB()
  519. //
  520. //    Description:
  521. //        Export everything currently selected as a reference.
  522. //
  523. {
  524.     string $saveType = "mayaAscii";
  525.     string $wsName = `workspace -q -fn`;
  526.  
  527.     if (`optionVar -exists defaultFileReferenceType`) {
  528.         $saveType = `optionVar -q defaultFileReferenceType`;
  529.     }
  530.     setWorkingDirectory $wsName $saveType "scene";
  531.  
  532.     fileBrowser "referenceEdExportAsReference" "Export Reference" $saveType 101;
  533. }
  534.  
  535. global proc referenceEdRemoveCB()
  536. //
  537. //    Description:
  538. //        Removed the file selected in the reference editor.
  539. //
  540. {
  541.     global string $_selectedFile[];
  542.     if (size($_selectedFile) == 1 && size($_selectedFile[0]) > 0) {
  543.         string $result = `confirmDialog -t "Remove Reference"
  544.                             -m ("Removing the Reference to "
  545.                                     +$_selectedFile[0]+" is Not Undoable.")
  546.                                     -b "Remove" -b "Cancel" -db "Cancel"`;
  547.         if ($result == "Remove") {
  548.             file -rr $_selectedFile[0];
  549.             $_selectedFile[0] = "";
  550.         }
  551.     }
  552. }
  553.  
  554. global proc referenceEdSelectCB()
  555. //
  556. //    Description:
  557. //        A callback to select all of the contents of the file selected
  558. //        in the reference editor.
  559. //
  560. {
  561.     global string $_selectedFile[];
  562.     if (size($_selectedFile) == 1 && size($_selectedFile[0]) > 0) {
  563.         file -sa $_selectedFile[0];
  564.     }
  565. }
  566.  
  567. global proc referenceEdUnloadCB()
  568. //
  569. //    Description:
  570. //        A callback to unload a reference.
  571. //
  572. {
  573.     global string $_selectedFile[];
  574.     global string $_selectedRef[];
  575.     if (size($_selectedFile) == 1 && size($_selectedFile[0]) > 0) { 
  576.         //    Save the connections in the reference node.    
  577.         //
  578.         file -ur $_selectedRef[0] $_selectedFile[0];
  579.     }
  580. }
  581.  
  582. global proc referenceEdLoadCB()
  583. //
  584. //    Description:
  585. //        A callback to load a reference.
  586. //
  587. {
  588.     global string $_selectedFile[];
  589.     if (size($_selectedFile) == 1 && size($_selectedFile[0]) > 0) {
  590.         global string $_selectedRef[];
  591.  
  592.         file -lr $_selectedRef[0] $_selectedFile[0];
  593.     }
  594. }
  595.  
  596. global proc referenceEdSelectedUpdateList()
  597. //
  598. //    Description:
  599. //        Updates the reference list based on the selected.
  600. //
  601. {
  602.     global string $_selectedFile[];
  603.     global string $_selectedRef[];
  604.  
  605.     if (size($_selectedFile) == 0 || size($_selectedRef) == 0) {
  606.         return;
  607.     }
  608.  
  609.     referenceEdUpdateList($_selectedFile[0], $_selectedRef[0]);
  610. } // referenceEdSelectedUpdateList
  611.  
  612.  
  613. global proc referenceEdUpdateList(string $addFile, string $refNode)
  614. //
  615. //    Description:
  616. //        Adds the file to the list replace list.
  617. //
  618. {
  619.     //    Set the length of the list to 5.
  620.     //
  621.     int $MAX_SIZE = 5;
  622.     int $nFn = `getAttr -size ($refNode + ".fn")`;
  623.     int $nItems = ($nFn >= $MAX_SIZE) ? $MAX_SIZE : $nFn;
  624.  
  625.     //    Two cases:
  626.     //    1: The file was never used before, then pop this
  627.     //       to the top of the list and shove everything 
  628.     //       else down.
  629.     //    2: The file was used before, then put the file at the
  630.     //       top and push everything down to the file's old
  631.     //       level.
  632.     //
  633.     int $usedBefore = false;
  634.     int $usedItem = 0;
  635.     for ($i = 0; $i < $nItems; $i++) {
  636.         string $fileName = `getAttr ($refNode+".fn["+$i+"]")`;
  637.         if ($fileName == $addFile) {
  638.             $usedBefore = true;
  639.             $usedItem = $i;
  640.             break;
  641.         }
  642.     }
  643.  
  644.     if (!$usedBefore) {
  645.         if ($nItems < $MAX_SIZE) {
  646.             $nItems++;
  647.         }
  648.     }
  649.  
  650.     string $newStr = $addFile;
  651.     string $swap;
  652.     for ($i = 0; $i < $nItems; $i++) {
  653.         $swap = `getAttr ($refNode + ".fn["+$i+"]")`;
  654.         setAttr -type "string" ($refNode+".fn["+$i+"]") $newStr;
  655.         $newStr = $swap;
  656.  
  657.         if ($usedBefore && $usedItem == $i) {
  658.             break;
  659.         }
  660.     }
  661. } // referenceEdUpdateList
  662.  
  663. global proc referenceEdReplaceCB()
  664. //
  665. //    Description:
  666. //        A callback to replace the currently loaded reference file with 
  667. //        a new reference file, while still keeping the same reference node.
  668. //
  669. {
  670.     global string $_selectedFile[];
  671.  
  672.     if (size($_selectedFile) == 1 && size($_selectedFile[0]) > 0) {
  673.         global string $_selectedRef[];
  674.         global string $gReplaceReferenceNode;
  675.  
  676.         $gReplaceReferenceNode = $_selectedRef[0];
  677.  
  678.         string $replacedFile = $_selectedFile[0];
  679.         if (size($_selectedRef[0]) == 0) {
  680.             //    If a reference node does not exist, create a new one.
  681.             //
  682.             if (catch(`file -rfn $_selectedRef[0] $_selectedFile[0]`)) {
  683.                 //    If adding the reference node failed, then the replace
  684.                 //    will also fail.
  685.                 //
  686.                 return;
  687.             }
  688.  
  689.             $gReplaceReferenceNode = `file -q -rfn $_selectedFile[0]`;
  690.         }
  691.  
  692.         // Add the file to the list of replace files. Set the list
  693.         // length to 5.
  694.         //
  695.         string $refNode = $gReplaceReferenceNode;
  696.         referenceEdSelectedUpdateList();
  697.  
  698.         projectViewer ReplaceReference;
  699.     }    
  700. }
  701.  
  702. global proc buildReferenceEdRecentMenu(string $parentMenu)
  703. //
  704. //    Description:
  705. //        Builds the recently selected files for a specific reference. If one
  706. //        of the items is selected, the reference is replaced with that file.
  707. //         The new file should move to the head of the list.
  708. {
  709.     global string $_selectedFile[];
  710.     global string $_selectedRef[];
  711.  
  712.     string $menu = ($parentMenu + "|referenceEdRecentFilesItem");
  713.     if (size($_selectedRef) == 0) {
  714.         menu -e -deleteAllItems $menu;
  715.         return;
  716.     }
  717.  
  718.     //    Get the number of files previously used.
  719.     //
  720.     int $nListFiles = `getAttr -size ($_selectedRef[0]+".fn")`;
  721.     
  722.     //    Get the list of files.
  723.     //
  724.     int $i, $j;
  725.     string $fileList[];
  726.     for ($i = 0, $j = 0; $i < $nListFiles; $i++) {
  727.         string $nextFile = `getAttr ($_selectedRef[0]+".fn["+$i+"]")`;
  728.         if (size($nextFile) == 0) {
  729.             continue;
  730.         }
  731.         $fileList[$j++] = $nextFile;
  732.     }
  733.  
  734.     //    Pack the list, if necessary.
  735.     //
  736.     int $nFiles = `size($fileList)`;
  737.     if ($i != $j) {
  738.         for ($i = 0; $i < $nListFiles; $i++) {
  739.             string $fileName;
  740.             if ($i < $nFiles) {
  741.                 $fileName = $fileList[$i];
  742.             }
  743.             setAttr -type "string" ($_selectedRef[0]+".fn["+$i+"]") $fileName;
  744.         }
  745.     } 
  746.  
  747.     string $oldParent = `setParent -q -menu`;
  748.     setParent -menu $parentMenu;
  749.     
  750.     //    Check and see if the current menu contains the same names as
  751.     //    the list in the reference node.
  752.     //
  753.     string $localList[] = `menu -q -itemArray $menu`;
  754.     int $nLocalItems = `size($localList)`;
  755.     if ($nFiles == $nLocalItems) {
  756.         int $i;
  757.         for ($i = 0; $i < $nLocalItems; $i++) {
  758.             if ($localList[$i] != $fileList[$i]) {
  759.                 break;
  760.             }
  761.         }
  762.         if ($i == $nLocalItems) {
  763.             return;
  764.         }
  765.     }
  766.  
  767.     menu -e -deleteAllItems $menu;
  768.     setParent -menu $menu;
  769.  
  770.     for ($i = 0; $i < $nFiles; $i++) {
  771.         string $cmd = ("referenceEdSelectedUpdateList();" +
  772.                         "file -lr \"" + $_selectedRef[0] + 
  773.                        "\" \"" + $fileList[$i] + "\";");
  774.         menuItem -l $fileList[$i] -c $cmd;
  775.     }
  776.  
  777.     setParent -menu $oldParent;
  778. }
  779.